﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading;
using System.Globalization;
using Nivdal.AuxCode;
using System.Text;

namespace Nivdal
{
    public partial class Rubric : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Title = Resources.Resource.Default_PageTitle + ", " + Resources.Resource.Rubric_PageTitle;
            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
            OnlineUser ou = (OnlineUser)Session["User"];

            string RubricID="";

            if (Request.QueryString["Id"] == null)
                Response.Redirect("~/Newspaper.aspx");
            else
            {
                RubricID = Request.QueryString["Id"];
                RubricIdHiddenField.Value = RubricID;
                ShowAllHyperlnk.NavigateUrl = "~/NewsPaper.aspx?Id=" + GND.ReadNivdalIntData("RubricId", "Nivdal_GetNewsPaperByRubric", RubricID);
            }

            string UserNewsPaperPriv = (ou.NewsPaperPrivsLevel);
            if (UserNewsPaperPriv == "2" || UserNewsPaperPriv == "3")
                AddStoryPanel.Visible = true;
            if (UserNewsPaperPriv == "3")
                AdminPanel.Visible = true;

            OuterAdminPanel.Visible = (AddStoryPanel.Visible || AdminPanel.Visible);

            if (GND.ReadNivdalBoolData("RubricId", "Nivdal_GetNewspaperDir", RubricID))
                NewspaperDirPanel.Direction = ContentDirection.RightToLeft;
            else
                NewspaperDirPanel.Direction = ContentDirection.LeftToRight;

            
            if (!IsPostBack)
            {
                NewsPaperTopStoriesDataSource.SelectParameters.Add("UserId", ou.UserId);
                string rubricdescription = GND.ReadNivdalStringData("RubricId", "Nivdal_GetRubricInfo", RubricID);
                RubricDescriptionLabel.Text = rubricdescription;
                int start = rubricdescription.IndexOf("<b>");
                int finish = rubricdescription.IndexOf("</b>");
                RubricNameTitleLabel.Text = rubricdescription.Substring(start + 3, finish - start + 3);
            }

            
        }
        protected override void InitializeCulture()
        {
            OnlineUser ou = (OnlineUser)Session["User"];
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(ou.UICulture);
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(ou.Culture);
        }

        protected string GetRubricTitleClass(object rubricId)
        {
            if (rubricId.ToString() == RubricIdHiddenField.Value)
                return ("NewspaperTitleHihglightedStyle");
            return ("NewspaperTitleStyle");            
        }
    
    }
}